package com.linwen.excise.leetcode;

/**
 * @ClassName _80删除有序数组中的重复项2
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/26 12:14 AM
 * @Version 1.0
 */
public class _80删除有序数组中的重复项2 {
    public static void main(String[] args) {
        int[] nums = new int[]{0,0,1,1,1,1,2,3,3};
        System.out.println(removeDuplicates(nums));

    }

    public static int removeDuplicates(int[] nums) {
        if(nums.length<2){
            return nums.length;
        }
        int fast = 1;
        int slow = 0;
        int tempCount = 1;
        while (fast < nums.length){
            if (nums[fast] == nums[slow]){
                tempCount++;
                if (tempCount <= 2) {
                    nums[++slow] = nums[fast];
                }

            }else {
                tempCount = 1;
                nums[++slow] = nums[fast];
            }
            fast++;
        }
        return slow+1;
    }
}
